package metamodel.parser;


import metamodel.*;

import java.util.HashMap;
import java.util.Map;

/**
 * User: fleipold
 * Date: 23-Nov-2007
 * Time: 15:19:08
 */
public class LabelMap {
    private final Map<String, ClassNode> map = new HashMap<String, ClassNode>();

    public LabelMap(ClassNode meta) {
        descent(meta);
         System.out.println("done");
    }

    private void descent(ClassNode meta) {
        if (meta.getLabel()!=null)
            map.put(meta.getLabel(),meta);
         if (meta instanceof PolyClassNode){
             PolyClassNode polyClassNode = (PolyClassNode) meta;
             for (ClassNode node : polyClassNode.getSubClazzes()) {
                 if (! (node instanceof TypeReference)){
                     descent(node);
                 }
             }
         }

        for (Property property : meta.getProperties()){
            if (property instanceof ObjectReference){
                ObjectReference or= (ObjectReference) property;
                if (! (or.getElementType() instanceof TypeReference)){
                    descent(or.getElementType());
                }
            }

        }


    }

    public ClassNode get(String key) {
        return map.get(key);
    }
}
